<?php
/**
 * Eka Framework 0.3.0
 *
 * @copyright Copyright (c) 2008 Alexey Yu. Chuprina <656b61@gmail.com> (http://php-eka.googlecode.com)
 * @license http://www.opensource.org/licenses/mit-license.php MIT License
 *
 * @version $Id$
 */

require_once 'Eka/File.php';

/**
 * Eka_File_Music
 *
 * @package File
 * @subpackage Music
 */
class Eka_File_Music extends Eka_File
{
	protected $type = self::TYPE_MUSIC;

	protected $duration = null;

	public function __construct($file)
	{
		parent::__construct($file);

		$info = array();
		$output = shell_exec(self::$cmdFfmpeg . ' -i ' . escapeshellarg($this->file) . ' 2>&1');
		$pattern = '`Duration: (\d+):(\d+):([\d\.]+)`sU';
		if (!preg_match($pattern, $output, $info)) {
			include_once 'Eka/File/Exception.php';
			throw new Eka_File_Exception('The file is not music');
		}

		$this->duration = ($info[1] * 3600) + ($info[2] * 60) + ceil($info[3]);
	}

	public function getDuration()
	{
		return $this->duration;
	}
}